package com.bio;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;

public class TimeClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket();
        socket.setTcpNoDelay(true);
        socket.connect(new InetSocketAddress("127.0.0.1", 8080));
        BufferedReader reader = null;
        PrintWriter writer = null;
        try {
            reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));

            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            while (true) {
                String order = in.readLine();
                if ("exit".equalsIgnoreCase(order)) {
                    socket.close();
                    return;
                }
                writer.println(order);
                writer.flush();
                System.out.println(reader.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (writer != null) {
                writer.flush();
                writer.close();
                writer = null;
            }
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
